/*********************************
* John Clayton
* Assignment 4
* CS362
* Random Test Adventurer
*********************************/

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>

#define NUM_TESTS 10000 //Number of times to run the test

int main(){
   int i,
       j,
       k,
       player,
       numPlayers,
       handPos,
       bonus = 0,
       newSize,
       preCoins,
       postCoins,
       preHandCount,
       preDeckCount,
       preDiscardCount;
   int kCards[10] = {adventurer, ambassador, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
   struct gameState *state;
   enum CARD card = adventurer;
   enum CARD firstCard = adventurer;
   enum CARD lastCard = treasure_map;
   PlantSeeds(3);
   SelectStream(0);
   assert(state != 0);

   printf("Beginning testing card: Adventurer\n**************************************\n");
   for(i = 0; i <= NUM_TESTS; i++){
      state = newGame();
      numPlayers = (((int) (Random() * 1000))%4) + 1;
      initializeGame(numPlayers, kCards,(int) (Random()*256), state);
      player = state->whoseTurn;

      //New deck size for player between 5-60.
      newSize = (((int) (Random() * 1000))%56)+5;
      state->deckCount[player] = newSize;

      //First 2 cards are gold and the next are kingdom cards
      state->deck[player][0] = gold;
      state->deck[player][1] = gold;
      for(j = 2; j < newSize; j++)
	 state->deck[player][j] = (int) (Random() * 256) % (lastCard - firstCard) + firstCard;

      //Shuffle deck
      shuffle(player, state);

      //Put an adventurer at the beginning of the hand
      handPos = 0;
      state->hand[player][handPos] = adventurer;

      //Find the starting number of coins in hand, size of hand, size of deck, and size of discard
      updateCoins(player, state, bonus);
      preCoins = state->coins;
      preHandCount = state->handCount[player];
      preDeckCount = state->deckCount[player];
      preDiscardCount = state->discardCount[player];

      //Play card
      cardEffect(card, 0, 0, 0, state, handPos, &bonus);

      //Find final number of coins in hand
      updateCoins(player, state, bonus);
      postCoins = state->coins;

      printf("[Test %d]:\n", i);
      if(preCoins + 6 == postCoins)
	 printf("\tPASS on getting coins. (should have: %d, has: %d)\n", preCoins + 6, postCoins);
      else
	 printf("\tFAIL on getting coins. (should have: %d, has: %d)\n", preCoins + 6, postCoins);
      if((preDeckCount - 2) - state->discardCount[player] == state->discardCount[player] - preDiscardCount - 1)
	 printf("\tPASS on extra discards. (deck lost: %d, discard gained: %d)\n", (preDeckCount - 2) - state->discardCount[player], state->discardCount[player] - preDiscardCount - 1);
      else
	 printf("\tFAIL on extra discards. (deck lost: %d, discard gained: %d)\n", (preDeckCount - 2) - state->discardCount[player], state->discardCount[player] - preDiscardCount - 1);
      if(preHandCount + 1 == state->handCount[player])
	 printf("\tPASS on hand size. (should have: %d, has: %d)\n", preHandCount + 1, state->handCount[player]);
      else
	 printf("\tFAIL on hand size. (should have: %d, has: %d)\n", preHandCount + 1, state->handCount[player]);
   }
   printf("Ending testing card: Adventurer\n***********************************\n");
   return 0;
}
